﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Reconciliation.Data
{
    public partial class CaseAuditorComment
    {
        public static Domain.CaseAuditorComment MapDataToDomain(Data.CaseAuditorComment dataCaseAuditorComment)
        {
            Domain.CaseAuditorComment domainCaseAuditorComment = new Reconciliation.Domain.CaseAuditorComment();
            domainCaseAuditorComment.CaseAuditorCommentID = dataCaseAuditorComment.CaseAuditorCommentID ;
            domainCaseAuditorComment.Comment = dataCaseAuditorComment.Comment ;
            domainCaseAuditorComment.DateTime = dataCaseAuditorComment.DateTime ;
            domainCaseAuditorComment.User = User.MapDataToDomain(dataCaseAuditorComment.User) ;
            return domainCaseAuditorComment;
        }

        public static Data.CaseAuditorComment MapDomainToData(Domain.CaseAuditorComment domainCaseAuditorComment)
        {
            Data.CaseAuditorComment dataAuditorClientComment = new Reconciliation.Data.CaseAuditorComment();
            dataAuditorClientComment.Comment = domainCaseAuditorComment.Comment;
            dataAuditorClientComment.DateTime = DateTime.Now;
            dataAuditorClientComment.CaseReference.EntityKey = new System.Data.EntityKey("ReconciliationEntities.Case", "CaseID", domainCaseAuditorComment.Case.CaseID);
            dataAuditorClientComment.UserReference.EntityKey = new System.Data.EntityKey("ReconciliationEntities.User", "UserID", domainCaseAuditorComment.User.UserID);            
            return dataAuditorClientComment;
        }

        public static List<Domain.CaseAuditorComment> GetCaseAuditorComment(int caseID)
        {
            List<Domain.CaseAuditorComment> domainCaseAuditorCommentList = new List<Reconciliation.Domain.CaseAuditorComment>();
            Domain.CaseAuditorComment domainCaseAuditorComment = new Reconciliation.Domain.CaseAuditorComment();
            ReconciliationEntities recEnt = new ReconciliationEntities();
            List<Data.CaseAuditorComment> dataCaseAuditorComment = recEnt.CaseAuditorComment.Include("User").Where(c => c.Case.CaseID.Equals(caseID)).ToList();
            foreach (Data.CaseAuditorComment cac in dataCaseAuditorComment)
            {
                domainCaseAuditorComment = CaseAuditorComment.MapDataToDomain(cac);
                domainCaseAuditorCommentList.Add(domainCaseAuditorComment);
            }
            return domainCaseAuditorCommentList;
        }

        public static void SetCaseAuditorComment(Domain.CaseAuditorComment domainCaseAuditorComment)
        {
            using(ReconciliationEntities recEnt = new ReconciliationEntities())
            {
                Data.CaseAuditorComment dataAuditorComment = Data.CaseAuditorComment.MapDomainToData(domainCaseAuditorComment);
                recEnt.AddToCaseAuditorComment(dataAuditorComment);
                recEnt.SaveChanges();
            }
        }
    }
}
